#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#define MAX_SIZE 10

typedef struct TREENODE TreeNode;
typedef int ElementType;
typedef struct QUEEN Queen;
typedef Queen ListNode;

struct TREENODE{
	ElementType elm;
	TreeNode *left;
	TreeNode *right;
};

struct QUEEN{
	ElementType item;
	ListNode *next;
	ListNode *tail;
};

ListNode *initQueen(void);
void inQueen(Queen*,ElementType);
_Bool queenEmpty(Queen*);
ElementType outQueen(Queen*);
TreeNode* addNode(TreeNode*,ElementType);
void preOrder(TreeNode*,Queen*);
void inOrder(TreeNode*,Queen*);
_Bool checkSame(TreeNode*,TreeNode*);
_Bool compareQueen(Queen *q1,Queen *q2);
void prtQueen(Queen*);

int main(void){
	ElementType inputSeq[MAX_SIZE];
	TreeNode *orig=NULL;
	TreeNode *check=NULL;
	int N,L;
	while( scanf("%d",&N) && N!=0 ){
		scanf("%d",&L);
		for(int i=0;i<N;i++){
			scanf("%d",&inputSeq[i]);
			orig=addNode(orig,inputSeq[i]);
		}
		for(int i=0;i<L;i++){
			check=NULL;
			for(int j=0;j<N;j++){
				scanf("%d",&inputSeq[j]);
				//scanf("%d",&inputSeq[i]);
				check=addNode(check,inputSeq[j]);
			}
			if( checkSame(orig,check))
				printf("Yes\n");	
			else
				printf("No\n");
		}
		//preOrder(orig);
		orig=NULL;
	}
	return 0;
}


TreeNode* addNode(TreeNode *root,ElementType elm){
	if( root == NULL ){
		root=malloc(sizeof(TreeNode));
		root->elm=elm;
		root->left=root->right=NULL;
		return root;
	}else{
		TreeNode **father;
		TreeNode *head=root;
		while( root ){
			if( elm > (root->elm) ){
				father=&(root->right);
				root=root->right;
			}
			else{//	elm < (root->elm)
				father=&(root->left);
				root=root->left;	
			}
		}
		root=malloc(sizeof(TreeNode));
		root->elm=elm;
		root->left=root->right=NULL;
		*father=root;
		return head;
	}
}

void preOrder(TreeNode *head,Queen *list){
	if( !head )
		return;
	//printf("%d ",head->elm);
	inQueen(list,head->elm);
	preOrder(head->left,list);
	preOrder(head->right,list);
	return ;
}
void inOrder(TreeNode *head,Queen *list){
	if( !head )
		return;
	//printf("%d ",head->elm);
	preOrder(head->left,list);
	inQueen(list,head->elm);
	preOrder(head->right,list);
	return;
}



_Bool checkSame(TreeNode *t1,TreeNode *t2){
	Queen *q1i=initQueen();
	Queen *q2i=initQueen();
	Queen *q1p=initQueen();
	Queen *q2p=initQueen();
	inOrder(t1,q1i);
	inOrder(t2,q2i);
	preOrder(t1,q1p);
	preOrder(t2,q2p);
//prtQueen(q1i);
//printf("\n");
//prtQueen(q2i);
//printf("\n");
//prtQueen(q1p);
//printf("\n");
//prtQueen(q2p);
	if( compareQueen(q1i,q2i) && compareQueen(q1p,q2p) ){
		return true;
	}
	return false;
}

_Bool compareQueen(Queen *q1,Queen *q2){
	ElementType e1,e2;
	while( !queenEmpty(q1) && !queenEmpty(q2) ){
		e1=outQueen(q1);
		e2=outQueen(q2);
		if( e1 != e2 )
			return false;
	}
	if( queenEmpty(q1) && queenEmpty(q2) )
		return true;
	else
		return false;
}

ListNode *initQueen(void){
	ListNode *ret=malloc(sizeof(ListNode));
	ret->next=NULL;
	ret->tail=NULL;
	return ret;
}
void inQueen(Queen *head,ElementType elm){
	ListNode *new=malloc(sizeof(ListNode));
	new->next=NULL;
	new->item=elm;
	if( head->tail ){
		head->tail->next=new;
		head->tail=new;
	}else{
		head->tail=new;
		head->next=new;
	}
	return;
}
_Bool queenEmpty(Queen *head){
	if( head->next )
		return false;
	else
		return true;
}

ElementType outQueen(Queen *head){
	ElementType elm=head->next->item;
	ListNode *tmp=head->next->next;
	free(head->next);
	head->next=tmp;
	return elm;
}

void prtQueen(Queen *q){
	while( q->next ){
		printf("%d-",q->next->item);
		q=q->next;
	}
}
